package cn.minsh.lims.eoms.modules.app.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.minsh.lims.eoms.common.utils.PageUtils;
import cn.minsh.lims.eoms.common.utils.Query;

import cn.minsh.lims.eoms.modules.app.dao.RepairOrderRecordDao;
import cn.minsh.lims.eoms.modules.app.entity.RepairOrderRecordEntity;
import cn.minsh.lims.eoms.modules.app.service.RepairOrderRecordService;


@Service("repairOrderRecordService")
public class RepairOrderRecordServiceImpl extends ServiceImpl<RepairOrderRecordDao, RepairOrderRecordEntity> implements RepairOrderRecordService {

    @Autowired
    private RepairOrderRecordDao repairOrderRecordDao ;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<RepairOrderRecordEntity> page = this.page(
                new Query<RepairOrderRecordEntity>().getPage(params),
                new QueryWrapper<RepairOrderRecordEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<RepairOrderRecordEntity> listByOrderId(Long orderId) {
        QueryWrapper<RepairOrderRecordEntity> wrapper = new QueryWrapper<>() ;
        wrapper.eq("repair_order_id",orderId) ;
        wrapper.orderByAsc("id") ;
        return repairOrderRecordDao.selectList(wrapper);
    }

    @Override
    public List<RepairOrderRecordEntity> listByOperatorAndOrderId(Long userId, Long orderId) {
        QueryWrapper<RepairOrderRecordEntity> wrapper = new QueryWrapper<>() ;
        wrapper.eq("repair_order_id",orderId) ;
        wrapper.and(wrapper1->wrapper1.eq("operator_id",userId).or().like("operation","%"+userId+"%")) ;
        wrapper.orderByAsc("id") ;
        return repairOrderRecordDao.selectList(wrapper);
    }

    @Override
    public List<RepairOrderRecordEntity> listByOperatorId(Long userId) {
        QueryWrapper<RepairOrderRecordEntity> wrapper = new QueryWrapper<>() ;
        wrapper.eq("operator_id",userId) ;
        wrapper.orderByDesc("id") ;
        return repairOrderRecordDao.selectList(wrapper);
    }

}